package com.hainatong.jcmvvmbase.mainhome.adapter;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.hainatong.jcmvvmbase.Constants;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.ItemFileViewBinding;
import com.hainatong.jcmvvmbase.mainhome.entity.FunctionEntity;
import org.jetbrains.annotations.NotNull;

public class FileItemAdapter extends BaseQuickAdapter<FunctionEntity, BaseDataBindingHolder<ItemFileViewBinding>>
{

    public FileItemAdapter()
    {
        super(R.layout.item_file_view);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemFileViewBinding> bindingHolder, FunctionEntity functionEntity)
    {
        ItemFileViewBinding binding = bindingHolder.getDataBinding();


        if( binding != null )
        {
            // doc   pdf  等  将 functionTag 设置为 DocumentFile

            if( functionEntity.getContentTag().equals( Constants.DOCUMENT_TAG)  )
            {
                if( functionEntity.getTitle().endsWith(".doc") )
                {
                    Glide.with(getContext())
                            .load( R.mipmap.ic_file )
                            .into( binding.ivFunSub );
                }

                if( functionEntity.getTitle().endsWith(".pdf")  )
                {
                    Glide.with(getContext())
                            .load( R.mipmap.ic_pdf )
                            .into( binding.ivFunSub );
                }
            }

            binding.setFileFunction( functionEntity );
            binding.executePendingBindings();
        }

    }
}
